package com.cy.pj.module.controller;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
public class JsonController {
    @RequestMapping("/doConvertMapToJson")
    public Map<String,Object> doConvertMapToJson(){
        Map<String,Object>map = new HashMap<>();
        map.put("name","tony");
        map.put("state",true);
        return map;
    }

    @RequestMapping("/doHandleRequestParam01")
    public String doHandleRequestParam01(String name){
        return "request params is"+name;
    }


    @RequestMapping("/doHandleRequestParam02")
    public String doHandleRequestParam02(String name,@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate){
        return "request params name="+name+"/startDate="+startDate;
    }


    /**
     * Rest 风格的url定义
     * rest 风格:一种软件框架编码风格,这种风格中定义了url的一种格式,其语法:
     * /a/b/{c}/d/{e},其中{}内部内容为变量,例如
     * 1)a/b/100/d/200
     * 2)a/b/e/d/f
     * 加入在方法参数中想获取rest url中变量值,使用@PathVariable
     * 注解对方法参数进行描述
     * 前提是方法参数名需要与url中的变量名相同;
     * @param id
     * @return
     */
    @RequestMapping("/doHandleRequestParam03/{id}")
    public String doHandleRequestParam03(@PathVariable Integer id) {
        return "request params id="+id;
    }


}
